    package com.example.smartcity.ui.SmartCommynity;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.graphics.Rect;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import com.example.smartcity.R;
import com.example.smartcity.ui.Adapter.ManagerCarAdapter;
import com.example.smartcity.ui.Bean.ManagerCarBean;
import com.google.android.material.textfield.TextInputEditText;

import java.util.ArrayList;

public class ManagerCar extends AppCompatActivity {

    private RecyclerView RV_CarMessage;
    private static ArrayList<ManagerCarBean> CarMessage = new ArrayList();
    private TextView TV_newCar;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_manager_car);
        RV_CarMessage = findViewById(R.id.RV_CarMessage);
        TV_newCar = findViewById(R.id.TV_newCar);
        initView();
    }
    public void setBack(View view){
        this.finish();
    }

    public void initView(){
        loadMessage();
        TV_newCar.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ManagerCarBean managerCarBean = new ManagerCarBean("","","","","","");
                CarMessage.add(managerCarBean);
                loadMessage();
            }
        });
    }

    public void loadMessage(){
        RV_CarMessage.addItemDecoration(new RecyclerView.ItemDecoration() {
            @Override
            public void getItemOffsets(@NonNull Rect outRect, @NonNull View view, @NonNull RecyclerView parent, @NonNull RecyclerView.State state) {
                outRect.top = 20;
            }
        });
        LinearLayoutManager manager = new LinearLayoutManager(this);
        manager.setOrientation(RecyclerView.VERTICAL);
        RV_CarMessage.setLayoutManager(manager);
        ManagerCarAdapter adapter = new ManagerCarAdapter(R.layout.mangercaritemlayout,CarMessage);
       adapter.SetOnItemClickListener(new ManagerCarAdapter.OnItemClickListener() {
           @Override
           public void OnItemClickListener(int position, View itemView) {
               ManagerCarBean bean = CarMessage.get(position);
               TextInputEditText text1 = itemView.findViewById(R.id.CarMessage1);
               bean.setCarMessage1(text1.getText().toString());
               TextInputEditText text2 = itemView.findViewById(R.id.CarMessage2);
               bean.setCarMessage2(text2.getText().toString());
               TextInputEditText text3 = itemView.findViewById(R.id.CarMessage3);
               bean.setCarMessage3(text3.getText().toString());
               TextInputEditText text4 = itemView.findViewById(R.id.CarMessage4);
               bean.setCarMessage4(text4.getText().toString());
               TextInputEditText text5 = itemView.findViewById(R.id.CarMessage5);
               bean.setCarMessage5(text5.getText().toString());
               TextInputEditText text6 = itemView.findViewById(R.id.CarMessage6);
               bean.setCarMessage6(text6.getText().toString());
               Toast.makeText(ManagerCar.this, "提交成功", Toast.LENGTH_SHORT).show();
           }
       });
        RV_CarMessage.setAdapter(adapter);
    }
}
